package com.algo.core.processor;

import com.algo.core.HttpRequestWrapper;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * 专门存放请求的queue
 */
public class HttpRequestQueue {

    private LinkedBlockingQueue<HttpRequestWrapper> queue =
            new LinkedBlockingQueue<HttpRequestWrapper>();

    /**
     * 往队列里面添加数据
     * @param httpRequestWrapper
     * @return
     */
    public boolean offer(HttpRequestWrapper httpRequestWrapper) {
        return queue.offer(httpRequestWrapper);
    }

    /**
     * 从队列中取元素，没有元素时线程会等待
     * @return
     * @throws InterruptedException
     */
    public HttpRequestWrapper take() throws InterruptedException {
        return queue.take();
    }

    /**
     * 队列的长度
     * @return
     */
    public int size() {
        return queue.size();
    }


}
